//==============================================================================
// militaryUpgradeMen
//==============================================================================
rule militaryUpgradeMen
   minInterval 31
   active
   runImmediately
{
	if(cMyCulture != cCultureEgyptian)
	{
      		xsDisableSelf();
		return;
	}
		
   	//Must be setup for resources before we do any of this.
	if ( (kbSetupForResource(kbBaseGetMainID(cMyID), cResourceWood, 25.0, 400) == false) ||
	     (kbSetupForResource(kbBaseGetMainID(cMyID), cResourceFood, 25.0, 400) == false) )
		return;

	//Define Armory Progression (all civs)

	int apid = aiPlanCreate("armoryUpgradeMen",cPlanProgression);
   	if (apid >= 0)
   	{ 
      		aiPlanSetVariableBool(apid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(apid, 75);
		aiPlanSetEscrowID(apid, cMilitaryEscrowID);
      		aiPlanSetBaseID(apid, kbBaseGetMainID(cMyID));
      
		aiPlanSetNumberVariableValues(apid, cProgressionPlanGoalTechID, 11, true);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
			aiPlanSetNumberVariableValues(apid, cProgressionPlanGoalTechID, 17, true);

		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 0, cTechLeatherArmor);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 1, cTechWoodenShields);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 2, cTechBow);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 3, cTechSword);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 4, cTechSaddle);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 5, cTechStirrups);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 6, cTechQuiver);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 7, cTechChainMail);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 8, cTechShields);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 9, cTechPlateMail);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 10, cTechHelmets);
      
		if (aiGetWorldDifficulty() == cDifficultyNightmare)
		{
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 11, cTechVisors);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 12, cTechLongSword);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 13, cTechArmGuard);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 14, cTechThumbRing);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 15, cTechFletching);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 16, cTechTwoHandedSword);
		}

		aiPlanSetActive(apid);
	}
	else
		aiPlanDestroy(apid);

	//Define Foundry Progression (all civs)

	int fpid = aiPlanCreate("foundryUpgradeMen",cPlanProgression);
   	if (fpid >= 0)
   	{ 
      		aiPlanSetVariableBool(fpid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(fpid, 75);
		aiPlanSetEscrowID(fpid, cMilitaryEscrowID);
      		aiPlanSetBaseID(fpid, kbBaseGetMainID(cMyID));
      
		aiPlanSetNumberVariableValues(fpid, cProgressionPlanGoalTechID, 5, true);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
			aiPlanSetNumberVariableValues(fpid, cProgressionPlanGoalTechID, 8, true);

		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 0, cTechCopper);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 1, cTechBronzeAlloy);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 2, cTechMetalCasting);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 3, cTechMetalHardening);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 4, cTechAnnaAngron);
      
		if (aiGetWorldDifficulty() == cDifficultyNightmare)
		{
			aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 5, cTechAnnealing);
			aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 6, cTechMeteoricIron);
			aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 7, cTechTheLoreofTelchar);
		}

		aiPlanSetActive(fpid);
	}
	else
		aiPlanDestroy(fpid);

   	//Define Military Progression Plan
   	int pid=aiPlanCreate("militaryUpgradeMen", cPlanProgression);
   	if (pid >= 0)
   	{ 
      		aiPlanSetVariableBool(pid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(pid, 75);
		aiPlanSetEscrowID(pid, cMilitaryEscrowID);
      		aiPlanSetBaseID(pid, kbBaseGetMainID(cMyID));
      
		// Gondor
	   	if (cMyCiv == cCivIsis)
	   	{
			aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 6, true);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
				aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 9, true);
         			
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 0, cTechMediumCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 1, cTechMediumInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 2, cTechMediumArchers);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 3, cTechHeavyCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 4, cTechHeavyInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 5, cTechHeavyArchers);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
			{
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 6, cTechChampionCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 7, cTechChampionInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 8, cTechChampionArchers);
			}

         			aiPlanSetActive(pid);
   		}
   		// Rohan
   		else if (cMyCiv == cCivRa)
   		{
			aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 5, true);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
				aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 9, true);
         			
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 0, cTechTheodenEdnew);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 1, cTechSonsofEorl);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 2, cTechKnightsoftheRiddermark);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 3, cTechMusterofRohan);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 4, cTechTheHelmofHammerhand);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
			{
	         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 5, cTechLordsoftheRiddermark);
	         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 6, cTechFoalsofShadowfax);
	         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 7, cTechForthEorlingas);
	         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 8, cTechLordsofRohan);
			}

         			aiPlanSetActive(pid);
   		}
   		// Dunedain
   		else if (cMyCiv == cCivSet)
   		{
			aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 6, true);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
				aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 9, true);
         			
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 0, cTechMediumCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 1, cTechMediumInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 2, cTechMediumArchers);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 3, cTechHeavyCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 4, cTechHeavyInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 5, cTechHeavyArchers);

			if (aiGetWorldDifficulty() == cDifficultyNightmare)
			{
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 6, cTechChampionCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 7, cTechChampionInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 8, cTechChampionArchers);
			}

         			aiPlanSetActive(pid);
   		}

	}
	else
		aiPlanDestroy(pid);


      	xsDisableSelf();
}

